package picture

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
	"github.com/flipped-aurora/gin-vue-admin/server/model/picture"
	pictureReq "github.com/flipped-aurora/gin-vue-admin/server/model/picture/request"
	"github.com/flipped-aurora/gin-vue-admin/server/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

type PictureApi struct {
}

var pictureService = service.ServiceGroupApp.PictureServiceGroup.PictureService

// CreatePicture 创建Picture
// @Tags Picture
// @Summary 创建Picture
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body picture.Picture true "创建Picture"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /picture/createPicture [post]
func (pictureApi *PictureApi) CreatePicture(c *gin.Context) {
	var picture picture.Picture
	_ = c.ShouldBindJSON(&picture)
	if err := pictureService.CreatePicture(picture); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeletePicture 删除Picture
// @Tags Picture
// @Summary 删除Picture
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body picture.Picture true "删除Picture"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /picture/deletePicture [delete]
func (pictureApi *PictureApi) DeletePicture(c *gin.Context) {
	var picture picture.Picture
	_ = c.ShouldBindJSON(&picture)
	if err := pictureService.DeletePicture(picture); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeletePictureByIds 批量删除Picture
// @Tags Picture
// @Summary 批量删除Picture
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除Picture"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /picture/deletePictureByIds [delete]
func (pictureApi *PictureApi) DeletePictureByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := pictureService.DeletePictureByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdatePicture 更新Picture
// @Tags Picture
// @Summary 更新Picture
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body picture.Picture true "更新Picture"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /picture/updatePicture [put]
func (pictureApi *PictureApi) UpdatePicture(c *gin.Context) {
	var picture picture.Picture
	_ = c.ShouldBindJSON(&picture)
	if err := pictureService.UpdatePicture(picture); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindPicture 用id查询Picture
// @Tags Picture
// @Summary 用id查询Picture
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query picture.Picture true "用id查询Picture"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /picture/findPicture [get]
func (pictureApi *PictureApi) FindPicture(c *gin.Context) {
	var picture picture.Picture
	_ = c.ShouldBindQuery(&picture)
	if repicture, err := pictureService.GetPicture(picture.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"repicture": repicture}, c)
	}
}

// GetPictureList 分页获取Picture列表
// @Tags Picture
// @Summary 分页获取Picture列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query pictureReq.PictureSearch true "分页获取Picture列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /picture/getPictureList [get]
func (pictureApi *PictureApi) GetPictureList(c *gin.Context) {
	var pageInfo pictureReq.PictureSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if list, total, err := pictureService.GetPictureInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}

// PictureCreate 创建Picture
// @Tags Picture
// @Router /picture/create [post]
func (pictureApi *PictureApi) PictureCreate(c *gin.Context) {

}

// PictureDelete 删除Picture
// @Tags Picture
// @Router /picture/delete [delete]
func (pictureApi *PictureApi) PictureDelete(c *gin.Context) {

}
